//js userd by register/page_body
$(document).ready(function()
{
	 var validator = $("#reg_form").validate({	 
	     rules:{      
		   	email: { required: true, email: true, maxlength: 50, check_email: true },
		   	nick: { required: true, maxlength: 20, check_nick: true},
		   	pass: { required: true , minlength: 6, maxlength: 20},
		   	repass: { required: true , minlength: 6, maxlength: 20, check_repass: true },  
		   	vcode: { check_vcode: true }
	     },
	     messages:{
	        email: { required:"需要输入电子邮箱", email:"电子邮箱格式不正确", maxlength:'最多输入50个字符',check_email:'该邮箱地址已经存在'},        
	        nick: {required:"需要输入昵称", maxlength:'最多输入20个字符', check_nick: '该昵称已经存在'},
	        pass: { required:"需要输入密码", minlength:'密码最少6个字符', maxlength:'密码最多20个字符'},
	        repass: { required:"需要输入密码", minlength:'密码最少6个字符', maxlength:'密码最多20个字符', check_repass: '两次确认的密码不一致'},
	        vcode: { check_vcode: "验证码错误" }
	     },
	     //离开焦点时验证,按键不验证
         onkeyup: false,
	     submitHandler: function(form) 
	     {
	    	 return true; //form.submit();
	     }
	   });
	   
	   jQuery.validator.addMethod("check_vcode", function(value, element) 
	   {
		   
		   var result=true;
		   if(value=='')
			   result=false;
		   else
		   {
			   $.ajax({
	               type: 'Get',
	               url: edp_domain_url + 'ajax_vcode_validate/?tiny=1&code='+value,
	               async: false,
	               dataType: 'json',
	               timeout: 500,
	               success: function(data)
	               {
			    	  result=data.res;    
	               }
	           });
		   }
		   return result;
		}, "");
	   
	   jQuery.validator.addMethod("check_repass", function(value, element) 
			   {
		   			return $('#repass').val() == $('#pass').val();
				   
				}, "");
	   
	   //Validate Function to check the email address overlap
	   // True表示Email未被占用，false表示被占用
	   jQuery.validator.addMethod("check_email", function(value, element) 
	   {
		   var result=true;
		   $.ajax({
			     type: 'Get',
			     url: edp_domain_url + 'ajax_register_check/?tiny=1&type=email&email='+value,
			     async: false,
			     dataType: 'json',
			     timeout: 5000,
			     success: function(data)
			     {
					  result=data.res;    
			     }
		   });
		   return result;
	    }, "");
	   
	   //Validate Function to check the nick name overlap
	   // True表示nick未被占用，false表示被占用
	   jQuery.validator.addMethod("check_nick", function(value, element) 
	   {
		   var result=true;
		   $.ajax({
			     type: 'Get',
			     url: edp_domain_url + 'ajax_register_check/?tiny=1&type=nick&nick='+value,
			     async: false,
			     dataType: 'json',
			     timeout: 5000,
			     success: function(data)
			     {
					  result=data.res;    
			     }
		   });
		   return result;
	    }, "");
	   
	   //Function to refresh the validate image
		$("#virefresh").click(function(){
			$("#vimg").attr('src', edp_domain_url + 'vcode/?tiny='+Math.random());
		})
});

$(document).ready(function()
{
	function jump(count) 
	{   
		window.setTimeout(function()
		{   
			count--;   
			if(count > 0) 
			{   
				$('#num').attr('innerHTML', count);   
				jump(count);   
			} 
			else 
			{   
				window.location.href=$("#auto_jump_url").val();   
			}   
		}, 1000);   
	};   
	
	if($("#auto_jump_url").size()>0)
		jump(5);
});